package com.cdz.controller;

import com.cdz.commen.R;
import com.cdz.domain.Firmware;
import com.cdz.form.InitBleForm;
import com.cdz.form.OneDataForm;
import com.cdz.form.UpdateForm;
import com.cdz.service.OtaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/cdz/ota")
public class OtaController {

    @Autowired
    private OtaService otaService;

    @GetMapping("/getBinAll")
    public ResponseEntity<Iterable<Firmware>> getBinAll() {
        return ResponseEntity.ok(otaService.getBinAll());
    }

    @GetMapping("/getMaintenanceInfo")
    public R<?> getMaintenanceInfo() {
        return otaService.getMaintenanceInfo();
    }


    @PostMapping("/sendFile")
    public ResponseEntity<String> uploadAllFile(@RequestParam("file") MultipartFile file) {
        return otaService.uploadAllFile(file);
    }

    @PostMapping("/updateOneFile")
    public R<?> updateOneFile(@ModelAttribute OneDataForm oneDataForm) throws IOException {
        return otaService.updateOneFile(oneDataForm);
    }

    @GetMapping("/transferBin")
    public R<?> transferBin(@RequestParam String chargingPileId){
        return otaService.transferBin(chargingPileId);
    }

    @GetMapping("/ifUpdate")
    public R<?> ifUpdate(@RequestParam String chargingPileId){
        return otaService.ifUpdate(chargingPileId);
    }

    @PostMapping("/setUpdate0")
    public R<?> setUpdate0(@RequestBody UpdateForm updateForm){
        return otaService.setUpdate0(updateForm);
    }
//    @PostMapping("/setUpdate1")
//    public R<?> setUpdate1(){
//        return otaService.setUpdate1();
//    }

    
}

